package com.prs.crm.dao.cqunicom.impl;


import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cqunicom.PieListDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cqunicom.PieList;
import com.prs.crm.domain.cqunicom.PoplarOrder;
import com.prs.crm.domain.hr.Person;
/**
 * @author  WangTing
 *
 * 创建时间：2011-3-10 
 * 
 */

public class PieListDaoImpl extends BaseDaoImpl<PieList> implements PieListDao {

	@SuppressWarnings("unchecked")

	@Override
	public Collection<PieList> getAllPieList() {
		// TODO Auto-generated method stub
		return (Collection<PieList>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(PieList.class);
				return criteria.list();
			}
			
		});
	}

	@Override
	public Integer delPieList() {
		return (Integer) this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
							Query query = session.createQuery("delete from PieList");
							return query.executeUpdate();
				        }   
				 } );
	}

	@Override
	public List<PieList> getByPersonA(final Person person) {
		 return (List<PieList>) this.getHibernateTemplate().execute(
					new HibernateCallback()
					{
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(PieList.class);
				        	criteria.add(Restrictions.eq("personMp",person));				        	
							return criteria.list();
				 				        	
				        }
					}
			);
	}

	@Override
	public List<PieList> getByPersonB(final Person person) {
		 return (List<PieList>) this.getHibernateTemplate().execute(
					new HibernateCallback()
					{
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(PieList.class);
				        	criteria.add(Restrictions.eq("visitPerson",person));				        	
							return criteria.list();
				 				        	
				        }
					}
			);
	}

	@Override
	public List<PieList> getByPersonC(final Person person) {
		return (List<PieList>) this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(PieList.class);
			        	criteria.add(Restrictions.eq("personPie",person));				        	
						return criteria.list();
			 				        	
			        }
				}
		);
	}

	
}
